home *** CD-ROM | disk | FTP | other *** search
- /*
- check if a file is up to date.
- chkutod file [-d n]
- [-h n]
- result is true or false.
- -d n allows n days difference
- -h n allows n hours difference
- -not inverses result
-
- */
- #include <stdio.h>
- #include <time.h>
- #include <sys/stat.h>
- #include <sys/types.h>
-
- main(argc,argv)
- int argc;
- char *argv[];
- {
- int i,n,m,err,passed,hours,days,maxdiff;
- time_t acttime,filetime;
- char c,s[80],z[80];
- struct stat stbuf;
-
- maxdiff = 0;
- i = 1;
-
- if(checkopt(argc,argv,"-h",z)) maxdiff = 3600 * atoi(z);
- if(checkopt(argc,argv,"-d",z)) maxdiff = 86400 * atoi(z);
- if(checkopt(argc,argv,"-not",z)) i = -1;
- if(maxdiff==0) help();
-
-
- acttime=time(NULL); /* get actual time */
-
- err = stat(argv[1],&stbuf);
- filetime = stbuf.st_mtime; /* last modification */
-
- passed = difftime(acttime,filetime); /* number of seconds passed */
-
- hours = passed / 3600;
- days = hours / 24;
-
- n = maxdiff - passed;
- n = i * n;
-
- if(n > 0) exit(0);
- exit(-1);
-
- }
-
- help()
- {
-
- printf("check if a file is up to date.\n");
- printf("chkutod file [-d n]\n");
- printf(" [-h n]\n");
- printf("result is true or false.\n");
- printf(" -d n allows n days difference\n");
- printf(" -h n allows n hours difference\n");
- printf(" -not inverses result\n");
- exit(0);
- }
-
-
- checkopt(argc,argv,s,sv)
- int argc;
- char *argv[],s[],sv[];
- {
- int n,m,i,erg;
- char c,z[80];
-
- erg=0;
- for(n=1;n<argc;n++) {
- if(strcmp(argv[n],s)==0) {
- erg = -1;
- strcpy(sv,argv[n+1]);
- }
- }
- return(erg);
- }
-